;; My emacs configuration file;
;; Author: freelsen@gmail.com;

(provide 'lsemacs)

;; default directory
(setq default-directory "~/lsen/")
(setq command-line-default-directory "~/.emacs.d/ls/tmp/")
(setq make-backup-files nil) ; auto backup

(add-to-list 'load-path "~/.emacs.d/ls/lsthird/")
(require 'org-include-img-from-zip)

;(server-start) ; server

;; window/frame;
(add-to-list 'default-frame-alist '(height . 40))
(add-to-list 'default-frame-alist '(width . 90))

(setq inhibit-startup-message t) ; close welcome page; 2012-02-12;
(setq frame-title-format "@%b") ; title bar message;2011-08-20;
;(setq column-number-mode t) ;; show column number;
(tool-bar-mode nil) ; shut down toolbar
(setq-default cursor-type 'bar) ; cursor
(setq visible-bell t) ;; shut off the error bell

(global-font-lock-mode t) ;; grama highlight;

(setq-default line-spacing 6)
;(set-default-font "Courier New-24") ;; font;
;(setq default-frame-alist (font . "Courier New 12"))
;(set-default-font "-outline-新宋体-normal-normal-normal-mono-20-*-*-*-c-*-iso8859-1")

;@150317: scroll one line at a time (less "jumpy" than defaults)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq scroll-step 1) ;; keyboard scroll one line at a time

(auto-image-file-mode t) ;; show picture

(setq default-buffer-file-coding-system 'utf-8) ;150225;
;(prefer-coding-system 'utf-8)

;copy,paste with other program
;(set-selection-coding-system 'cn-gb-2312)
;(global-set-key "\367" (quote clipboard-kill-ring-save))

(remove-hook 'find-file-hooks 'vc-find-file-hook) ;150225, disable loading vc-git;

; 2013-04-06;
;(setq viper-mode t)
;(require 'viper)

;; 2011-08-23 Tab Space;
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq c-basic-offset 4)
(add-hook 'c++-mode-hook
  '(lambda ()
  (c-set-style "awk")))

;archive;

;(require 'arc-mode)
;(setq 'archive-subfile-mode t)
;(add-to-list 'auto-mode-alist '("\\.org\\'" . arc-mode))

;;org-mode-2011-08-21;
(add-to-list 'load-path "~/.emacs.d/org-8.2.10/lisp/")
(require 'org-install)

(autoload 'iimage-mode "iimage" "Support Inline image minor mode." t)
(autoload 'turn-on-iimage-mode "iimage" "Turn on Inline image minor mode." t)
;(setq org-startup-with-inline-images t)

(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))

(add-hook 'org-mode-hook 'turn-on-font-lock)
(add-hook 'org-mode-hook
	(lambda () (setq truncate-lines nil)))
(setq org-startup-indented t)
;;(setq org-startup-folded nil)
;;(setq org-agenda-inhibit-startup nil)
;(add-to-list 'load-path "~/.emacs.d/org-8.2.10/contrib/lisp/")
;(require 'org-toc)
;(setq org-toc-columns-show t)
;(setq org-toc-default-depth 2)
;(setq org-toc-follow-mode t)

(defun ls-org-cycle-current-headline-i ()
  (interactive)
  (org-cycle-internal-local))
(defun ls-org-cycle-current-headline ()
  (interactive)
  (outline-previous-heading)
  (org-cycle))
(global-set-key "\C-cs" 'ls-org-cycle-current-headline-i)

(defface ls-outline1
	'((((class color) (min-colors 88) (background light)) :foreground "dark slate blue" :underline t);"magenta");"dark cyan" );
	  (((class color) (min-colors 88) (background dark)) :foreground "LightSkyBlue")
	  (t:weight bold :underline t)) "ls-outline1" :group 'ls-face)
(defface ls-outline2
	'((((class color) (min-colors 88) (background light)) :foreground "sienna" :bold t);"VioletRed4");
	  (((class color) (min-colors 88) (background dark)) :foreground "LightSkyBlue")
	  (t:weight bold :underline t)) "ls-outline2" :group 'ls-face)
(defface ls-outline3
  '((((class grayscale) (background light)) :foreground "Gray90" :weight bold)
    (((class grayscale) (background dark))  :foreground "DimGray" :weight bold)
    (((class color) (min-colors 88) (background light)) :foreground "ForestGreen":bold t)
    (((class color) (min-colors 88) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
    (((class color) (min-colors 16) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 8)) :foreground "green")
    (t :weight bold :underline t)) "ls-outline3." :group 'ls-face)
(defface ls-outline4
  '((((class color) (min-colors 88) (background light)) :foreground "Blue1" );:bold t)
    (((class color) (min-colors 88) (background dark))  :foreground "LightSkyBlue")
    (((class color) (min-colors 16) (background light)) :foreground "Blue")
    (((class color) (min-colors 16) (background dark))  :foreground "LightSkyBlue")
    (((class color) (min-colors 8)) :foreground "blue" :weight bold)
    (t :inverse-video t :weight bold)) "ls-outline4.":group 'ls-faces)
(defface ls-emphasize1
  '((((class grayscale) (background light)) :foreground "DimGray" :slant italic)
    (((class grayscale) (background dark))  :foreground "LightGray" :slant italic)
    (((class color) (min-colors 88) (background light)) :foreground "red");"VioletRed4")
    (((class color) (min-colors 88) (background dark))  :foreground "LightSalmon")
    (((class color) (min-colors 16) (background light)) :foreground "RosyBrown")
    (((class color) (min-colors 16) (background dark))  :foreground "LightSalmon")
    (((class color) (min-colors 8)) :foreground "green")
    (t :slant italic)) "ls-emphasize1." :group 'ls-faces)
(defface ls-emphasize2
  '((((class grayscale) (background light)) :foreground "DimGray" :weight bold :slant italic)
    (((class grayscale) (background dark)) :foreground "LightGray" :weight bold :slant italic)
    (((class color) (min-colors 88) (background light)):foreground "magenta");"Firebrick")
    (((class color) (min-colors 88) (background dark)) :foreground "chocolate1")
    (((class color) (min-colors 16) (background light)) :foreground "red")
    (((class color) (min-colors 16) (background dark)) :foreground "red1")
    (((class color) (min-colors 8) (background light)) :foreground "red")
    (((class color) (min-colors 8) (background dark)) :foreground "yellow") 
	(t :weight bold :slant italic)) "ls-emphasize2." :group 'ls-faces)
(defface ls-emphasize3
  '((((class grayscale) (background light)) :foreground "Gray90" :weight bold)
    (((class grayscale) (background dark))  :foreground "DimGray" :weight bold)
    (((class color) (min-colors 88) (background light)) :foreground "ForestGreen")
    (((class color) (min-colors 88) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
    (((class color) (min-colors 16) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 8)) :foreground "green")
    (t :weight bold :underline t)) "ls-emphasize3." :group 'ls-face)

(defvar ls-emphasize1 'ls-emphasize1 "ls-emphasize1.")
(defvar ls-emphasize2 'ls-emphasize2 "ls-emphasize2.")
(defvar ls-emphasize3 'ls-emphasize3 "ls-emphasize3.")

(defvar ls-outline1 'ls-outline1 "ls-outline1.")
(defvar ls-outline2 'ls-outline2 "ls-outline2.")
(defvar ls-outline3	'ls-outline3 "ls-outline3.")
(defvar ls-outline4	'ls-outline4 "ls-outline4.")

;(font-lock-add-keywords 'org-mode '(("\\(\".*\"\\)" 1 ls-outline3)))
(font-lock-add-keywords 'org-mode '(("\\(\\s-\"[^\"\n]*\"\\)" 1 ls-emphasize2)))
(font-lock-add-keywords 'org-mode '(("\\(\\<'[^'\n]*'\\)" 1 ls-emphasize1 prepend)));font-lock-warning-face)))
(font-lock-add-keywords 'org-mode '(("\\(\\[[^\\[\n]*\\]\\)" 1 ls-emphasize3)))

(font-lock-add-keywords 'org-mode '(("\\(^.*{{{[1-2]\\)" 1 ls-outline1 t)))
(font-lock-add-keywords 'org-mode '(("\\(^.*{{{[3-9]\\)" 1 ls-outline2 t)))

(font-lock-add-keywords 'org-mode '(("\\(^>[^\n]*\\)" 1 ls-outline3 t)))
(font-lock-add-keywords 'org-mode '(("\\(^->.*\\)" 1 ls-outline4 t)))
;(font-lock-add-keywords 'org-mode '(("\\(^->.*\\)" 1 font-lock-function-name-face t)))
;(font-lock-add-keywords 'org-mode' ("[(]" "[)]"))
;(font-lock-add-keywords 'org-mode
;     '(("\\(^[^\n]\\{80\\}\\)\\(.*\\)$"
;        1 font-lock-warning-face prepend)))

;(defun font-lock-comment-annotations ()
;  "Highlight a bunch of well known comment annotations.
;This functions should be added to the hooks of major modes for programming."
;  (font-lock-add-keywords
;   nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|OPTIMIZE\\|HACK\\|REFACTOR\\):"
;          1 font-lock-warning-face t))))
;(add-hook 'org-mode-hook 'font-lock-comment-annotations)

;;(require 'org-toc)
;;(load "ls-toc")

;; modify; 2012-02-12;
;(global-set-key "\C-cl" 'org-store-link)
;(global-set-key "\C-ca" 'org-agenda)
;(global-set-key "\C-cb" 'org-iswitchb)

;(defun org-toggle-iimage-in-org ()
;"display images in your org file"
;(interactive)
;(if (face-underline-p 'org-link)
;(set-face-underline-p 'org-link nil)
;(set-face-underline-p 'org-link t))
;(iimage-mode))

(require 'cedet) ;; 2013-06-11; cedet ;

;; 2013-08-01; lua-mode;
;;(add-to-list 'load-path "d:/emacs/lua_mode")
;;(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
;;(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
;;(add-to-list 'interpreter-mode-alist '("lua" . lua-mode))

(defun ergoemacs-open-in-desktop ()
"Open the current file in desktop.
Works in Microsoft Windows, Mac OS X, Linux."
(interactive)
(cond
((string-equal system-type "windows-nt")
(w32-shell-execute "explore" (replace-regexp-in-string "/" "\\" default-directory t t)))
((string-equal system-type "darwin") (shell-command "open ."))
((string-equal system-type "gnu/linux")
(let ((process-connection-type nil)) (start-process "" nil "xdg-open" "."))
;; (shell-command "xdg-open .") ;; 2013-02-10 this sometimes froze emacs till the folder is closed. eg with nautilus
) ))

